package utils

import (
	"fmt"
	"github.com/spf13/viper"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"main.go/models"
)

var Db *gorm.DB

func InitConfig() {
	viper.SetConfigName("app")
	viper.AddConfigPath("config")
	err := viper.ReadInConfig()

	if err != nil {
		fmt.Println(err)
	}
	fmt.Println("config app:", viper.Get("app"))
	fmt.Println("config mysql:", viper.Get("mysql"))

}

func InitMysql() {

	Db, _ = gorm.Open(mysql.Open(viper.GetString("mysql.dns")), &gorm.Config{})
	user := models.UserBasic{}
	Db.Find(&user)
	fmt.Println(user)

}
